home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
flex
/
flexs237.zoo
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-05
|
20KB
|
773 lines
/* flex - tool to generate fast lexical analyzers */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Vern Paxson.
*
* The United States Government has rights in this work pursuant
* to contract no. DE-AC03-76SF00098 between the United States
* Department of Energy and the University of California.
*
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char rcsid[] =
"@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/main.c,v 2.9 90/06/27 23:48:24 vern Exp $ (LBL)";
#endif
#include "flexdef.h"
static char flex_version[] = "2.3";
/* declare functions that have forward references */
void flexinit PROTO((int, char**));
void readin PROTO(());
void set_up_initial_allocations PROTO(());
/* these globals are all defined and commented in flexdef.h */
int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt;
int interactive, caseins, useecs, fulltbl, usemecs;
int fullspd, gen_line_dirs, performance_report, backtrack_report, csize;
int yymore_used, reject, real_reject, continued_action;
int yymore_really_used, reject_really_used;
int datapos, dataline, linenum;
FILE *skelfile = NULL;
char *infilename = NULL;
int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
int current_mns, num_rules, current_max_rules, lastnfa;
int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
int *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum;
int current_state_type;
int variable_trailing_context_rules;
int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
int tecbck[CSIZE + 1];
int *xlation = (int *) 0;
int num_xlations;
int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
char **scname;
int current_max_dfa_size, current_max_xpairs;
int current_max_template_xpairs, current_max_dfas;
int lastdfa, *nxt, *chk, *tnxt;
int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
union dfaacc_union *dfaacc;
int *accsiz, *dhash, numas;
int numsnpairs, jambase, jamstate;
int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
int current_max_ccl_tbl_size;
Char *ccltbl;
char *starttime, *endtime, nmstr[MAXLINE];
int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
int num_backtracking, bol_needed;
FILE *temp_action_file;
FILE *backtrack_file;
int end_of_buffer_state;
char *action_file_name = NULL;
char **input_files;
int num_input_files;
char *program_name;
#ifndef SHORT_FILE_NAMES
static char *outfile = "lex.yy.c";
#else
static char *outfile = "lexyy.c";
#endif
static int outfile_created = 0;
static int use_stdout;
static char *skelname = NULL;
#ifdef atarist
long _stksize = -1L; /* need lots of stk+heap */
#endif
int main( argc, argv )
int argc;
char **argv;
{
flexinit( argc, argv );
readin();
if ( syntaxerror )
flexend( 1 );
if ( yymore_really_used == REALLY_USED )
yymore_used = true;
else if ( yymore_really_used == REALLY_NOT_USED )
yymore_used = false;
if ( reject_really_used == REALLY_USED )
reject = true;
else if ( reject_really_used == REALLY_NOT_USED )
reject = false;
if ( performance_report )
{
if ( interactive )
fprintf( stderr,
"-I (interactive) entails a minor performance penalty\n" );
if ( yymore_used )
fprintf( stderr, "yymore() entails a minor performance penalty\n" );
if ( reject )
fprintf( stderr, "REJECT entails a large performance penalty\n" );
if ( variable_trailing_context_rules )
fprintf( stderr,
"Variable trailing context rules entail a large performance penalty\n" );
}
if ( reject )
real_reject = true;
if ( variable_trailing_context_rules )
reject = true;
if ( (fulltbl || fullspd) && reject )
{
if ( real_reject )
flexerror( "REJECT cannot be used with -f or -F" );
else
flexerror(
"variable trailing context rules cannot be used with -f or -F" );
}
ntod();
/* generate the C state transition tables from the DFA */
make_tables();
/* note, flexend does not return. It exits with its argument as status. */
flexend( 0 );
/*NOTREACHED*/
}
/* flexend - terminate flex
*
* synopsis
* int status;
* flexend( status );
*
* status is exit status.
*
* note
* This routine does not return.
*/
void flexend( status )
int status;
{
int tblsiz;
char *flex_gettime();
if ( skelfile != NULL )
{
if ( ferror( skelfile ) )
flexfatal( "error occurred when writing skeleton file" );
else if ( fclose( skelfile ) )
flexfatal( "error occurred when closing skeleton file" );
}
if ( temp_action_file )
{
if ( ferror( temp_action_file ) )
flexfatal( "error occurred when writing temporary action file" );
else if ( fclose( temp_action_file ) )
flexfatal( "error occurred when closing temporary action file" );
else if ( unlink( action_file_name ) )
flexfatal( "error occurred when deleting temporary action file" );
}
if ( status != 0 && outfile_created )
{
if ( ferror( stdout ) )
flexfatal( "error occurred when writing output file" );
else if ( fclose( stdout ) )
flexfatal( "error occurred when closing output file" );
else if ( unlink( outfile ) )
flexfatal( "error occurred when deleting output file" );
}
if ( backtrack_report && backtrack_file )
{
if ( num_backtracking == 0 )
fprintf( backtrack_file, "No backtracking.\n" );
else if ( fullspd || fulltbl )
fprintf( backtrack_file,
"%d backtracking (non-accepting) states.\n",
num_backtracking );
else
fprintf( backtrack_file, "Compressed tables always backtrack.\n" );
if ( ferror( backtrack_file ) )
flexfatal( "error occurred when writing backtracking file" );
else if ( fclose( backtrack_file ) )
flexfatal( "error occurred when closing backtracking file" );
}
if ( printstats )
{
endtime = flex_gettime();
fprintf( stderr, "%s version %s usage statistics:\n", program_name,
flex_version );
fprintf( stderr, " started at %s, finished at %s\n",
starttime, endtime );
fprintf( stderr, " scanner options: -" );
if ( backtrack_report )
putc( 'b', stderr );
if ( ddebug )
putc( 'd', stderr );
if ( interactive )
putc( 'I', stderr );
if ( caseins )
putc( 'i', stderr );
if ( ! gen_line_dirs )
putc( 'L', stderr );
if ( performance_report )
putc( 'p', stderr );
if ( spprdflt )
putc( 's', stderr );
if ( use_stdout )
putc( 't', stderr );
if ( trace )
putc( 'T', stderr );
if ( printstats )
putc( 'v', stderr ); /* always true! */
if ( csize == 256 )
putc( '8', stderr );
fprintf( stderr, " -C" );
if ( fulltbl )
putc( 'f', stderr );
if ( fullspd )
putc( 'F', stderr );
if ( useecs )
putc( 'e', stderr );
if ( usemecs )
putc( 'm', stderr );
if ( strcmp( skelname